A Perl Script for Enconding HTML

This nifty little Perl Script encodes non-HTML characters like " into their HTML form ("). It is not currently complete- I need to extend the list of characters it translates, but it does most of the obvious ones.

The script looks like this:

#!perl

# EnHTML by Peter N. Lewis
# Jan 1997

use Mac::BBEdit;


$text = Copy;
if ($text eq ";";) {
  SetSelection( 0, 99999999 );
  $text = Copy;
}

PresetUndo;

$text =~ s/;/&;#59;/g;		# fix special chars
$text =~ s/&;/&;amp;/g;
$text =~ s/<;/&;lt;/g;
$text =~ s/>;/&;gt;/g;
$text =~ s/\";/&;quot;/g;
$text =~ s/";/&;quot;/g;
$text =~ s/";/&;quot;/g;
$text =~ s/'/'/g;
$text =~ s/'/'/g;


Paste $text;

SetUndo;

Home Contents Setup HTML Tricks Misc Feedback